﻿using Commands;
using ShapeManager;
using UserControls;
using System.Windows.Forms;

namespace Tools
{
    public class ToolObject : Tool
    {
        private Cursor cursor;
        /// <summary> 工具光标  </summary>
        protected Cursor Cursor
        {
            get
            {
                return cursor;
            }
            set
            {
                cursor = value;
            }
        }

        /// <summary> 鼠标抬起 </summary>
        public override void OnMouseUp(UImageWindow imageWindow, MouseEventArgs e)
        {
            imageWindow.ShapeList[0].Normalize();
            imageWindow.AddCommandToHistory(new CommandAdd(imageWindow.ShapeList[0]));
            imageWindow.ActiveTool = ShapeType.Pointer;
            imageWindow.Capture = false;
            imageWindow.Refresh();
        }

        /// <summary>
        /// 添加新的对象到图像窗体。
        /// 当用户在绘图区域点击左键时，会触发该功能。
        /// 并且有一个由 ToolObject 继承而来的工具处于激活状态时，就会调用该函数。
        /// </summary>
        protected void AddNewObject(UImageWindow imageWindow, DrawObject obj)
        {
            imageWindow.ShapeList.UnselectAll();
            obj.IsSelected = true;
            imageWindow.ShapeList.Add(obj);
            imageWindow.Capture = true;
            imageWindow.Refresh();
            imageWindow.SetDirty();
        }
    }
}
